
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
@protobuf-ts/runtime-rpc
Advanced tools
Runtime library for RPC clients generated by the protoc plugin "protobuf-ts"
@protobuf-ts/runtime-rpc is a TypeScript library that provides runtime support for Protocol Buffers (protobuf) and gRPC. It allows you to create and manage gRPC clients and servers, handle streaming, and perform unary calls with ease.
Unary Calls
This feature allows you to make unary gRPC calls. The code sample demonstrates how to set up a gRPC client and make a unary call to a service method.
const { GrpcWebFetchTransport } = require('@protobuf-ts/runtime-rpc');
const { MyServiceClient } = require('./my-service.client');
const transport = new GrpcWebFetchTransport({ baseUrl: 'http://localhost:8080' });
const client = new MyServiceClient(transport);
async function makeUnaryCall() {
const response = await client.myUnaryMethod({ myField: 'myValue' });
console.log(response);
}
makeUnaryCall();
Server Streaming
This feature allows you to handle server streaming gRPC calls. The code sample demonstrates how to set up a gRPC client and handle a server streaming method.
const { GrpcWebFetchTransport } = require('@protobuf-ts/runtime-rpc');
const { MyServiceClient } = require('./my-service.client');
const transport = new GrpcWebFetchTransport({ baseUrl: 'http://localhost:8080' });
const client = new MyServiceClient(transport);
async function handleServerStreaming() {
const stream = client.myServerStreamingMethod({ myField: 'myValue' });
for await (const response of stream.responses) {
console.log(response);
}
}
handleServerStreaming();
Client Streaming
This feature allows you to handle client streaming gRPC calls. The code sample demonstrates how to set up a gRPC client and handle a client streaming method.
const { GrpcWebFetchTransport } = require('@protobuf-ts/runtime-rpc');
const { MyServiceClient } = require('./my-service.client');
const transport = new GrpcWebFetchTransport({ baseUrl: 'http://localhost:8080' });
const client = new MyServiceClient(transport);
async function handleClientStreaming() {
const stream = client.myClientStreamingMethod();
stream.send({ myField: 'myValue1' });
stream.send({ myField: 'myValue2' });
stream.complete();
const response = await stream.response;
console.log(response);
}
handleClientStreaming();
Bidirectional Streaming
This feature allows you to handle bidirectional streaming gRPC calls. The code sample demonstrates how to set up a gRPC client and handle a bidirectional streaming method.
const { GrpcWebFetchTransport } = require('@protobuf-ts/runtime-rpc');
const { MyServiceClient } = require('./my-service.client');
const transport = new GrpcWebFetchTransport({ baseUrl: 'http://localhost:8080' });
const client = new MyServiceClient(transport);
async function handleBidirectionalStreaming() {
const stream = client.myBidirectionalStreamingMethod();
stream.send({ myField: 'myValue1' });
stream.send({ myField: 'myValue2' });
for await (const response of stream.responses) {
console.log(response);
}
}
handleBidirectionalStreaming();
@grpc/grpc-js is a gRPC library for Node.js that provides similar functionalities for creating and managing gRPC clients and servers. It supports unary, server streaming, client streaming, and bidirectional streaming calls. Compared to @protobuf-ts/runtime-rpc, @grpc/grpc-js is more mature and widely used in the Node.js ecosystem.
grpc-web is a JavaScript library that enables gRPC clients to communicate with gRPC servers from web browsers. It provides similar functionalities for making unary and streaming calls. Compared to @protobuf-ts/runtime-rpc, grpc-web is specifically designed for web environments and may require additional setup for server-side support.
grpc is the original gRPC library for Node.js, providing comprehensive support for gRPC clients and servers. It supports all types of gRPC calls and is widely used in production environments. Compared to @protobuf-ts/runtime-rpc, grpc is more established but may have a steeper learning curve for TypeScript developers.
Runtime library for RPC clients generated by protobuf-ts.
Install this plugin if you want to create your own RPC transport:
# with npm:
npm install @protobuf-ts/runtime-rpc
# with yarn:
yarn add @protobuf-ts/runtime-rpc
Or use one of the transports built with this package, for example Twirp via @protobuf-ts/twirp-transport or gRPC web via @protobuf-ts/grpcweb-transport.
To learn more about the types provided by this package, please read the MANUAL.
FAQs
Runtime library for RPC clients generated by the protoc plugin "protobuf-ts"
The npm package @protobuf-ts/runtime-rpc receives a total of 344,329 weekly downloads. As such, @protobuf-ts/runtime-rpc popularity was classified as popular.
We found that @protobuf-ts/runtime-rpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.